package edu.ilstu.mind.ise.ccp.impl.disruptor;

import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.BusySpinWaitStrategy;
import com.lmax.disruptor.SleepingWaitStrategy;
import com.lmax.disruptor.WaitStrategy;
import com.lmax.disruptor.YieldingWaitStrategy;

public class WaitStrategyParser {
	public static final String WAITSTRATEGY_BLOCKING = "BLOCKING";
	public static final String WAITSTRATEGY_YIELDING = "YIELDING";
	public static final String WAITSTRATEGY_SLEEPING = "SLEEPING";
	public static final String WAITSTRATEGY_BUSY_SPIN = "BUSY_SPIN";

	public static WaitStrategy parseWaitStrategy(String value) {
		// parse the wait strategy from a string
		if (WAITSTRATEGY_BLOCKING.equals(value)) {
			return new BlockingWaitStrategy();
		} else if (WAITSTRATEGY_YIELDING.equals(value)) {
			return new YieldingWaitStrategy();
		} else if (WAITSTRATEGY_SLEEPING.equals(value)) {
			return new SleepingWaitStrategy();
		} else if (WAITSTRATEGY_BUSY_SPIN.equals(value)) {
			return new BusySpinWaitStrategy();
		} else {
			throw new IllegalArgumentException(value + " is not a valid waitStrategy");
		}
	}

}
